<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class AdminController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }



    public function setlog($data,$content){

        $ip= $_SERVER["REMOTE_ADDR"];
        $user = Auth::user();
        $insert=array(
            'uid'=>$user->id,
            'username'=>$user->name,
            'ip'=>$ip,
            'type'=>'2',
            'content'=>$content,
            'data'=>$data,
            'created_at'=>date("Y-m-d H:i:s")
        );
        DB::table("action_log")->insert($insert);
    }

    public function sendsms($phone,$template,$code =""){
        include public_path("/sms/TopSdk.php");
        date_default_timezone_set('Asia/Shanghai');

//        $code = '{"code":"'.$key.'","product":"福瑞斯"}';

        $c = new \TopClient();
        $c ->appkey = config("app.dayukey") ;
        $c ->secretKey = config("app.dayusecretKey")  ;
        $req = new \AlibabaAliqinFcSmsNumSendRequest;
        $req ->setExtend( "" );
        $req ->setSmsType( "normal" );
        $req ->setSmsFreeSignName( "代理系统" );
        $req ->setSmsParam($code);
        $req ->setRecNum( $phone);
        $req ->setSmsTemplateCode( $template);
        $resp = $c ->execute( $req );


        $rest = $resp->result;

        if($rest->success == true){
            return  true;
        }else{
           return false;
        }
    }
}
